//
//  ComposeTopView.m
//  SinaWebo
//
//  Created by 王方伟 on 2017/1/19.
//  Copyright © 2017年 亦心. All rights reserved.
//

#import "ComposeTopView.h"
#import "NSDate+Extension.h"
#import "WeatherResponse.h"
#import "WeatherMother.h"
#import "AdInforModel.h"
#import <UIImageView+WebCache.h>

@interface ComposeTopView ()
@property (weak, nonatomic) IBOutlet UILabel *todayLabel;
@property (weak, nonatomic) IBOutlet UILabel *weekLabel;
@property (weak, nonatomic) IBOutlet UILabel *dateLable;
@property (weak, nonatomic) IBOutlet UILabel *weatherLabel;
@property (weak, nonatomic) IBOutlet UIImageView *adImageView;
@property (weak, nonatomic) IBOutlet UIButton *guideButton;

@end

@implementation ComposeTopView

+ (instancetype)composeTopView{
    return [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil].lastObject;
}

- (void)awakeFromNib{
    [super awakeFromNib];
    NSDate *date = [NSDate date];
    _todayLabel.text = [date toDateStr];
    _dateLable.text = [date dateStr];
    _todayLabel.text = [date toDateStr];
    _weekLabel.text = [date weekStr];
    NSMutableArray *imageArray = [NSMutableArray array];
    for (NSInteger index = 1; index <= 23; index++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"compose_weather_guide_anim_%zd", index]];
        [imageArray addObject:image];
    }
    _guideButton.imageView.animationImages = imageArray;
    _guideButton.imageView.animationRepeatCount = 100000;
    _guideButton.imageView.animationDuration = 1.2;
    
}

- (void)setFrame:(CGRect)frame{
    frame.size = CGSizeMake(kScreenW, 120);
    [super setFrame:frame];
}

- (void)setModel:(WeatherResponse *)model{
    _model = model;
    NSDate *date = [NSDate timeInterval:_model.weather_condition.publish_time];
    _dateLable.text = [date dateStr];
    _todayLabel.text = [date toDateStr];
    _weekLabel.text = [date weekStr];
    _weatherLabel.text = [NSString stringWithFormat:@"%@：%@ %@℃",_model.weather_condition.city,_model.weather_condition.weather_text, _model.weather_condition.temp];
    [_adImageView sd_setImageWithURL:[NSURL URLWithString:_model.ad_info.img_url] placeholderImage:[UIImage imageNamed:@"ad_img"]];
    [_guideButton.imageView startAnimating];
}

- (void)dealloc{
    [_guideButton.imageView stopAnimating];
}
@end
